package de.stefanocke.roo.wicket.base;

import java.util.ArrayList;
import java.util.List;

import org.springframework.roo.classpath.details.ConstructorMetadata;
import org.springframework.roo.model.JavaType;

import de.stefanocke.roo.wicket.MidUtils;
import de.stefanocke.roo.xtend.ItdBuilder;

/**
 * Base class for generated form components.
 * @author stoc
 *
 */
public abstract class ComponentMetadataBase<AV extends ComponentFilterAttributes> extends ModelClassAwareItdMetadataBase<AV>
		implements ComponentMetadata{
	public static final MidUtils midUtils = MidUtils.get(ComponentMetadataBase.class);

	public ComponentMetadataBase(ModelClassAwareMetadataCreationParams<AV> cmcp, ItdBuilder itdBuilder) {
		super(cmcp, itdBuilder);
	}

//	@Override
//	public JavaType[] getAllowedModelClasses() {
//		return this.getAnnotationValues().getAllowedModelClasses();
//	}

	@Override
	public JavaType[] getRequiredAnnotations() {
		return this.getAnnotationValues().getRequiredAnnotations();
	}
	
	@Override
	public List<? extends ConstructorMetadata> getConstructors() {
		//by default, a form component shall be created by calling its constructor
		//prefer "hand-written" constructors.
		List<ConstructorMetadata> ctors = new ArrayList<ConstructorMetadata>();
		ctors.addAll(governorTypeDetails.getDeclaredConstructors());	
		if(itdTypeDetails!=null){
			ctors.addAll(itdTypeDetails.getDeclaredConstructors());
		}
		return ctors;
	}
	
	@Override
	public boolean needsDecoration() {
		return false;
	}
	
	/**
	 * The metadata should also be considered as changed, if the ComponentFilterAttributes change.
	 */
	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		return super.hashCode() + getRequiredAnnotations().hashCode();
	}

}
